//
//  YWPublicBaseViewController+ZDTostView.m
//  YWBaseFrameWork
//
//  Created by mac on 16/7/17.
//  Copyright © 2016年 NeiQuan. All rights reserved.
//

#import "YWPublicBaseViewController+ZDTostView.h"
#import "MBProgressHUD.h"
#include <objc/runtime.h>
static const void *YWHttpRequestHUDKey = &YWHttpRequestHUDKey;
@implementation YWPublicBaseViewController (ZDTostView)

#pragma mark ----------MBProgressHUDmessage
- (void)showMBProgressHUDLoadingMessage:(NSString *)aMessage inView:(UIView *)aView {
    
    if (aView == nil) aView = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:aView animated:YES];
    hud.color=[ UIColor colorWithWhite:0.3 alpha:1.0];
    hud.labelText=aMessage;
    hud.detailsLabelColor=[UIColor whiteColor];
    hud.minSize = CGSizeMake(150.f, 100.f);
    [UIActivityIndicatorView appearanceWhenContainedIn:[ MBProgressHUD class], nil].color=[ UIColor whiteColor];;
    hud.mode=MBProgressHUDModeIndeterminate;
    hud.animationType=MBProgressHUDAnimationZoomOut; //动画
    hud.removeFromSuperViewOnHide = YES;
   [self setHUD:hud];
}
- (void)showMBProgressHUDLoadinginView:(UIView *)aView {
    if (aView == nil) aView = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:aView animated:YES];
     hud.color=[ UIColor colorWithWhite:0.3 alpha:1.0];
    [UIActivityIndicatorView appearanceWhenContainedIn:[ MBProgressHUD class], nil].color=[ UIColor whiteColor];;
    hud.mode=MBProgressHUDModeIndeterminate;
    hud.animationType=MBProgressHUDAnimationZoomOut; //动画
    hud.removeFromSuperViewOnHide = YES;
    [self setHUD:hud];
    
}
- (void)showMBProgressHUDErrorMessage:(NSString *)aMessage inView:(UIView *)aView{
    
    [self showMBProgressHUDImageName:@"tost_warning" Message:aMessage inView:aView];
}
- (void)showMBProgressHUDNetErrorMessage:(NSString *)aMessage inView:(UIView *)aView{
    
    [self showMBProgressHUDImageName:@"tost_netError" Message:aMessage inView:aView];

}
- (void)showMBProgressHUDSuccessMessage:(NSString *)aMessage inView:(UIView *)aView {
    
    [self showMBProgressHUDImageName:@"tost_succeed" Message:aMessage inView:aView];

}
-(void)showMBProgressHUDImageName:(NSString *)imagestring Message:(NSString *)aMessage inView:(UIView *)aView{
    
    if (aView == nil) aView = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:aView animated:YES];
    hud.color=[ UIColor colorWithWhite:0.3 alpha:1.0];
    hud.labelText = aMessage;
    hud.detailsLabelColor=[UIColor whiteColor];
    hud.minSize = CGSizeMake(150.f, 100.f);
    hud.customView = [[UIImageView alloc] initWithImage:[ UIImage imageNamed:imagestring]];
    hud.mode = MBProgressHUDModeCustomView;          // 再设置模式
    hud.animationType=MBProgressHUDAnimationZoomOut; //动画
    hud.removeFromSuperViewOnHide = YES;             // 隐藏时候从父控件中移除
   [hud hide:YES afterDelay: 0.50];          // 0.50秒之后再消失
}
- (MBProgressHUD *)HUD{
    return objc_getAssociatedObject(self, YWHttpRequestHUDKey);
}

- (void)setHUD:(MBProgressHUD *)HUD{
    
    objc_setAssociatedObject(self, YWHttpRequestHUDKey, HUD, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

#pragma mark ----------移除MBProgress
-(void)removeMBProgressView{
    
    [[self HUD]hide:YES];
}

@end
